package com.github.library.screenShot;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

/**
 * Created by Calvin.Wang on 12/3/2014.
 */
public class ClipImageBorderView extends View {
    private int mHorizontalPadding = 20;
    private int mVerticalPadding;
    private int mWidth;
    private int mBorderColor = Color.parseColor("#FFFFFF");
    private int mBorderWidth = 1;
    private Paint mPaint;

    public ClipImageBorderView(Context context) {
        this(context, null);
    }

    public ClipImageBorderView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ClipImageBorderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mBorderWidth = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, mBorderWidth, getResources()
                        .getDisplayMetrics());
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mWidth = getWidth() - 2 * mHorizontalPadding;
        mVerticalPadding = (getHeight() - mWidth) / 2;
//        mPaint.setColor(Color.parseColor("#aa000000"));
//        mPaint.setStyle(Style.FILL);
//        //draw left
//        canvas.drawRect(0, 0, mHorizontalPadding, getHeight(), mPaint);
//        //draw right
//        canvas.drawRect(getWidth() - mHorizontalPadding, 0, getWidth(),
//                getHeight(), mPaint);
////        draw top
//        canvas.drawRect(mHorizontalPadding, 0, getWidth() - mHorizontalPadding,
//                mVerticalPadding, mPaint);
//        //draw botton
//        canvas.drawRect(mHorizontalPadding, getHeight() - mVerticalPadding,
//                getWidth() - mHorizontalPadding, getHeight(), mPaint);
        //draw border
        mPaint.setColor(mBorderColor);
        mPaint.setStrokeWidth(mBorderWidth);
        mPaint.setStyle(Style.STROKE);
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2 - mHorizontalPadding, mPaint);
        //        canvas.drawRect(mHorizontalPadding, mVerticalPadding, getWidth()
//                - mHorizontalPadding, getHeight() - mVerticalPadding, mPaint);
    }

    public void setHorizontalPadding(int mHorizontalPadding) {
        this.mHorizontalPadding = mHorizontalPadding;
    }

}
